<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Header
 *
 * @author julien
 */
require_once 'Classes/View/ViewItems/ViewElement.php';
class Header extends ViewElement {
    private $title;
    private $css;
    private $js;
    private $charset;
    
    public function __construct($title="page",$css=null,$js=null){
        
        $this->setTitle($title);
        $this->js = array();
        $this->css = array();
        $this->addCSS($css);
        $this->addJS($js);
        $this->charset = "UTF-8";
        
    }
    
    public function setTitle($title){
        $this->title = $title;
    }
    
    public function addCSS($css){
        if(is_array($css)){
            foreach ($css as $key => $value) {
                $this->addCSS($value);
            }
        }
        else {
            if(!is_null($css)){
                $this->css[count($this->css)] = $css;                
            }
        } 
    }
    
    public function addJS($js){
        if(is_array($js)){
            foreach ($js as $key => $value) {
                $this->addJS($value);
            }
        }
        else {
            if(!is_null($js)){
                $this->js[count($this->js)] = $js;
            }
        }
    }
    
    public function setCharset($charset){
        $this->charset = $charset;
    }
    
    public function getHTML() {
       if($this->visible){

        $return ="";
        $return .='<head>'."\n";
        $return .='<meta http-equiv="Content-Type" content="text/html; charset='.$this->charset.'"/>'."\n";
        $return .='<title>'.$this->title.'</title>'."\n";
        foreach ($this->css as $css) {
            $return .= '<link type="text/css" href="'.$css.'" rel="stylesheet" />'."\n";
	}
        foreach ($this->js as $js) {
            $return .= '<script type="text/javascript" src="'.$js.'"></script>';
	}
        
        $return .='</head>';
        
        return $return;
       }
    }
}

?>
